import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/routes/observers/route_observer.dart';

class MyGetObserver extends GetObserver {


  static final List<Route<dynamic>> _routes = [];

  static List<String> get routeNames => _routes.map((r) => r.settings.name ?? '').toList();

  static bool contains(String name) => _routes.any((r) => r.settings.name == name);

  @override
  void didPop(Route route, Route? previousRoute) {
    _routes.remove(route);

    debugPrint("route----->didPop ${route.settings.name} pre -> ${previousRoute?.settings.name}");
    // MyBus.sendEventContent(previousRoute?.settings.name);
    super.didPop(route, previousRoute);
  }

  @override
  void didPush(Route route, Route? previousRoute) {
    _routes.add(route);
    // MyBus.sendEventContent(route?.settings.name);
    debugPrint("route----->didPush ${route.settings.name} pre -> ${previousRoute?.settings.name}");
    super.didPush(route, previousRoute);
  }
  @override
  void didRemove(Route route, Route? previousRoute) {
    _routes.remove(route);
    super.didRemove(route, previousRoute);
  }

  @override
  void didReplace({Route? newRoute, Route? oldRoute}) {
    if (oldRoute != null) _routes.remove(oldRoute);
    if (newRoute != null) _routes.add(newRoute);
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
  }
}
